package com.ischoolbar.programmer.filter;

/**
 * @Author lin
 **/

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginFilter implements Filter {
    public LoginFilter() {
    }
    public void destroy() {
    }
    public void doFilter(ServletRequest req, ServletResponse rep, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        HttpServletResponse response = (HttpServletResponse)rep;
        Object user = request.getSession().getAttribute("user");
        if (user == null) {
            response.sendRedirect("index.jsp");
        } else {
            chain.doFilter(request, response);
        }
    }

    public void init(FilterConfig arg0) throws ServletException {
    }
}

